<?php
  require_once('tpl/header.php');
?>

   <form action="">
		<input type="text" name="key">
		<input type="submit" value="搜索">
	</form>

<?php 
require_once("../system/loginCheck.php");
require_once("../system/dbConn.php");
connect();
 ?>


	<?php 
	$sql="select * from users";
	//如果点击了搜索提交按钮，sql就会发生变化 
	if (isset($_GET["key"])) {
			$key = trim($_GET["key"]);
			$sql="select * from users where uname like \"%{$key}%\"";
	}
	// echo "$sql"."<br>";
	$result=mysql_query($sql);//结果集
	$num=mysql_num_rows($result);
	if ($num==0) {
		echo "无记录";
		exit;
	}
	?>
	<table class="table table-hover" width="70%" align="center">
		<caption>注册用户信息列表（共 <?php echo $num; ?>名用户）</caption>
		<tr>
			<th>用户编号</th>
			<th>用户名</th>
			<th>性别</th>
			<th>生日</th>
			<th>头像</th>
			<th>电子邮件</th>
			<th>操作</th>
		</tr>
	<?php 
	//从结果集中取得一条记录,返回的是一个关联数组，下标分别是数据库中的各字段名。
	//$row=mysql_fetch_assoc($result);
	//var_dump($row);
	//!!!!!!!!!!!!!!
	while ($row=mysql_fetch_assoc($result)) {
	?>
	<tr>
		<td><?php echo $row["uid"]; ?></td>
		<td><?php echo $row["uname"]; ?></td>
		<td>
			<?php  
				if($row["gender"]) 
					echo "女";
				else
					echo "男";
			?>	
		</td>
		<td><?php echo $row["birthdate"]; ?></td>
		<td><img src="../images/<?php echo $row["pic"]; ?>" alt="图片丢失" width="80" > </td>
		<td><?php echo $row["email"]; ?></td>
		<td><a href="userEdit.php?uid=<?php echo $row["uid"]; ?>">修改</a> |<a href="doUserDelete.php?uid=<?php echo $row["uid"]; ?>" onclick="return confirm('真的删除吗')">删除</a></td>
	</tr>
	<?php	 
	}
	?>
</table>


<?php
  require_once('tpl/footer.php');
?>